package com.breaktian.assemble.utils;

import android.content.Context;
import android.support.annotation.NonNull;
import android.util.TypedValue;

/**
 * 尺寸换算
 * <p>
 * Created by An on 17/2/20.
 */
public final class DimensConversion {

    private DimensConversion() {
    }

    /**
     * sp -> pixel
     *
     * @param context Context
     * @param sp      Sp
     * @return pixel
     */
    @NonNull
    public static int spToPixel(@NonNull Context context, @NonNull float sp) {
        return (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp,
                context.getResources().getDisplayMetrics()) + 0.5f);
    }

    /**
     * dip -> pixel
     *
     * @param context Context
     * @param dp      Dip
     * @return Pixel
     */
    @NonNull
    public static int dpToPixel(@NonNull Context context, @NonNull float dp) {
        return (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
                context.getResources().getDisplayMetrics()) + 0.5f);
    }
}
